package com.longway.core.ext.excel.data;

import java.util.HashMap;
import java.util.List;
import java.util.Vector;

public class TableMeta
{
    private String table;
    private String primaryKey;
    private List<ColumnMeta> columns = new Vector<ColumnMeta>();
    private HashMap<String, Integer> columnKeys = new HashMap<String, Integer>();

    public TableMeta(String table)
    {
        this.table = table;
    }

    public String getTable()
    {
        return table;
    }

    public void setTable(String table)
    {
        this.table = table;
    }

    public List<ColumnMeta> getColumns()
    {
        return columns;
    }

    public ColumnMeta getColumn(int i)
    {
        if (i < columns.size()) {
            return columns.get(i);
        }

        return null;
    }

    public boolean hasColumnName(String name)
    {
       return (columnKeys.get(name)!=null); 
    }

    public void setColumns(List<ColumnMeta> columns)
    {
        this.columns = columns;
    }

    public HashMap<String, Integer> getColumnKeys()
    {
        return columnKeys;
    }

    public void setColumnKeys(HashMap<String, Integer> columnKeys)
    {
        this.columnKeys = columnKeys;
    }

    public void addColumn(ColumnMeta column)
    {
        this.columnKeys.put(column.getColumn(), columns.size());
        this.columns.add(column);
    }

    public String getPrimaryKey()
    {
        return primaryKey;
    }

    public void setPrimaryKey(String primaryKey)
    {
        this.primaryKey = primaryKey;
    }
}

